<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聊天室</title>
    <link rel="stylesheet" href="../../assets/lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../assets/css/chat/poll.css">
    <script src="../../assets/lib/layui/layui.js"></script>
    <script src="../../assets/lib/jQuery.js"></script>
    <script src="../../assets/js/const.js"></script>
</head>

<body>
    <div id="poll">
        <div id="chat-history" style="position: relative;">

        </div>
        <div id="submit-container">
            <textarea name="" placeholder="" class="layui-textarea" id="input-message"></textarea>
            <div>
                <button type="button" class="layui-btn" id="submit-btn" onclick="sendMessage()" lay-on="wait-send">发送</button>
            </div>
        </div>
    </div>
</body>
<script src="../../assets/js/chat.js"></script>
<script>
    layui.use(function () {
        var layer = layui.layer;
        var util = layui.util;
        // 事件
        util.on('lay-on', {
            'wait-send': function () {
                var message = $("#input-message").val()
                if (message.length === 0) {
                    layer.msg('不能发送空白消息', { icon: 0 }, function () {
                        // layer.msg('提示框关闭后的回调');
                    });
                } else {
                    var loadIndex = layer.msg('加载中', {
                        icon: 16,
                        shade: 0.01
                    });;
                    // 模拟关闭
                    setTimeout(function () {
                        layer.close(loadIndex)
                    }, 300);
                }
                if (USERNAME === '') {
                    layer.prompt({ title: '请输入昵称' }, function (value, index, elem) {
                        if (value === '') return elem.focus();
                        layer.msg('获得：' + util.escape(value)); // 显示 value
                        USERNAME = value
                        // 关闭 prompt
                        layer.close(index);
                    });
                }
            }
        })
    });
</script>

<script>
    function initialize() {

    }

    window.addEventListener('load', function () {

    })
</script>

</html>